﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using PreeRegisterModel;
using PreeRegisterBLL;
using System.Collections.Specialized;
using PreeRegisterBLL.Security;
using PreeRegisterModel;

namespace PreeRegister_WebAPI.Controllers
{
    public class CheckController : ApiController
    {

        [HttpPost]
        /// <summary>
        /// 查询体检报告列表
        /// </summary>
        /// <param name="any"></param>
        /// <returns></returns>
        public EncodeModel report(NameValueCollection any)
        {
            try
            {
                //获取JSON加密参数
                string jsonData = CommonBLL.RequestGetParam("jsonData").ToString();

                CheckReportListResponseModel CheckReportListResponseModel = new CheckReportListResponseModel();

                //解密头和内容信息
                string head_json = "";
                string body_json = "";
                string ErrMsg = "";
                string ReturnBodyJson = "";
                if (!ResultDecode.DecodeResult(jsonData, "check|report", ref head_json, ref body_json, ref ErrMsg))
                {
                    //序列化返回内容类
                    ReturnBodyJson = csSerialize.CheckReportListResponseModel(CheckReportListResponseModel);

                    //加密返回内容Json
                    return ResultDecode.EncodeResult(ReturnBodyJson);
                }

                //入口参数日志
                CommonBLL.WriteLog("check|report|Post|\r\n" + body_json + "\r\n\r\n");

                //反序列化请求字符串
                CheckReportListRequestModel CheckReportListRequestModel = csSerialize.CheckReportListRequestModel(body_json);

                //查询检查报告列表
                CheckReportListResponseModel = CheckReportBLL.GetCheckReportList(CheckReportListRequestModel);

                //序列化返回内容类
                ReturnBodyJson = csSerialize.CheckReportListResponseModel(CheckReportListResponseModel);

                //返回参数日志
                CommonBLL.WriteLog("check|report|Return|\r\n" + ReturnBodyJson + "\r\n\r\n");

                return ResultDecode.EncodeResult(ReturnBodyJson);
            }
            catch (Exception err)
            {
                CheckReportListResponseModel CheckReportListResponseModel = new CheckReportListResponseModel();

                //序列化返回内容类
                string ReturnBodyJson = csSerialize.CheckReportListResponseModel(CheckReportListResponseModel);

                //返回参数日志
                CommonBLL.WriteLog("check|report|Return|\r\n" + ReturnBodyJson + "\r\n\r\n");

                //加密返回内容Json
                return ResultDecode.EncodeResult(ReturnBodyJson);
            }
        }


        [HttpPost]
        /// <summary>
        /// 查询体检报告明细
        /// </summary>
        /// <param name="any"></param>
        /// <returns></returns>
        public EncodeModel detail(NameValueCollection any)
        {
            try
            {
                //获取JSON加密参数
                string jsonData = CommonBLL.RequestGetParam("jsonData").ToString();

                CheckReportDetailResponseModel CheckReportDetailResponseModel = new CheckReportDetailResponseModel();

                //解密头和内容信息
                string head_json = "";
                string body_json = "";
                string ErrMsg = "";
                string ReturnBodyJson = "";
                if (!ResultDecode.DecodeResult(jsonData, "check|detail", ref head_json, ref body_json, ref ErrMsg))
                {
                    //序列化返回内容类
                    ReturnBodyJson = csSerialize.CheckReportDetailResponseModel(CheckReportDetailResponseModel);

                    //加密返回内容Json
                    return ResultDecode.EncodeResult(ReturnBodyJson);
                }

                //入口参数日志
                CommonBLL.WriteLog("check|detail|Post|\r\n" + body_json + "\r\n\r\n");

                //反序列化请求字符串
                CheckReportDetailRequestModel CheckReportDetailRequestModel = csSerialize.CheckReportDetailRequestModel(body_json);

                //查询体检报告明细
                CheckReportDetailResponseModel = CheckReportBLL.GetCheckReportDetail(CheckReportDetailRequestModel);

                //序列化返回内容类
                ReturnBodyJson = csSerialize.CheckReportDetailResponseModel(CheckReportDetailResponseModel);

                //返回参数日志
                CommonBLL.WriteLog("check|detail|Return|\r\n" + ReturnBodyJson + "\r\n\r\n");

                return ResultDecode.EncodeResult(ReturnBodyJson);
            }
            catch (Exception err)
            {
                CheckReportDetailResponseModel CheckReportDetailResponseModel = new CheckReportDetailResponseModel();

                //序列化返回内容类
                string ReturnBodyJson = csSerialize.CheckReportDetailResponseModel(CheckReportDetailResponseModel);

                //返回参数日志
                CommonBLL.WriteLog("check|detail|Return|\r\n" + ReturnBodyJson + "\r\n\r\n");

                //加密返回内容Json
                return ResultDecode.EncodeResult(ReturnBodyJson);
            }
        }


        [HttpPost]
        /// <summary>
        /// 查询体检综检建议
        /// </summary>
        /// <param name="any"></param>
        /// <returns></returns>
        public EncodeModel advices(NameValueCollection any)
        {
            try
            {
                //获取JSON加密参数
                string jsonData = CommonBLL.RequestGetParam("jsonData").ToString();

                CheckAdvicesDetailResponseModel CheckAdvicesDetailResponseModel = new CheckAdvicesDetailResponseModel();

                //解密头和内容信息
                string head_json = "";
                string body_json = "";
                string ErrMsg = "";
                string ReturnBodyJson = "";
                if (!ResultDecode.DecodeResult(jsonData, "check|advices", ref head_json, ref body_json, ref ErrMsg))
                {
                    //序列化返回内容类
                    ReturnBodyJson = csSerialize.CheckAdvicesDetailResponseModel(CheckAdvicesDetailResponseModel);

                    //加密返回内容Json
                    return ResultDecode.EncodeResult(ReturnBodyJson);
                }

                //入口参数日志
                CommonBLL.WriteLog("check|advices|Post|\r\n" + body_json + "\r\n\r\n");

                //反序列化请求字符串
                CheckAdvicesListRequestModel CheckAdvicesListRequestModel = csSerialize.CheckAdvicesListRequestModel(body_json);

                //查询体检综检建议
                CheckAdvicesDetailResponseModel = CheckReportBLL.GetCheckAdvicesDetail(CheckAdvicesListRequestModel);

                //序列化返回内容类
                ReturnBodyJson = csSerialize.CheckAdvicesDetailResponseModel(CheckAdvicesDetailResponseModel);

                //返回参数日志
                CommonBLL.WriteLog("check|advices|Return|\r\n" + ReturnBodyJson + "\r\n\r\n");

                return ResultDecode.EncodeResult(ReturnBodyJson);
            }
            catch (Exception err)
            {
                CheckAdvicesDetailResponseModel CheckAdvicesDetailResponseModel = new CheckAdvicesDetailResponseModel();

                //序列化返回内容类
                string ReturnBodyJson = csSerialize.CheckAdvicesDetailResponseModel(CheckAdvicesDetailResponseModel);

                //返回参数日志
                CommonBLL.WriteLog("check|advices|Return|\r\n" + ReturnBodyJson + "\r\n\r\n");

                //加密返回内容Json
                return ResultDecode.EncodeResult(ReturnBodyJson);
            }
        }


    }
}